IT[X]
[ class tree: IT[X] ] [ index: IT[X] ] [ all elements ]

Source for file ITX.php

Documentation is available at ITX.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2001 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Ulf Wendel <ulf.wendel@phpdoc.de>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: ITX.php,v 1.9 2005/08/14 17:42:38 pajoye Exp $
  20. //
  21.  
  22. require_once('HTML/Template/IT.php');
  23. require_once 'HTML/Template/IT_Error.php';
  24.  
  25. /**
  26. * Integrated Template Extension - ITX
  27. *
  28. * With this class you get the full power of the phplib template class.
  29. * You may have one file with blocks in it but you have as well one main file
  30. * and multiple files one for each block. This is quite usefull when you have
  31. * user configurable websites. Using blocks not in the main template allows
  32. * you to modify some parts of your layout easily.
  33. *
  34. * Note that you can replace an existing block and add new blocks at runtime.
  35. * Adding new blocks means changing a variable placeholder to a block.
  36. *
  37. @author   Ulf Wendel <uw@netuse.de>
  38. @access   public
  39. @version  $Id: ITX.php,v 1.9 2005/08/14 17:42:38 pajoye Exp $
  40. @package  IT[X]
  41. */
  42.  
  43.     /**
  44.     * Array with all warnings.
  45.     * @var       array 
  46.     * @access    public
  47.     * @see       $printWarning, $haltOnWarning, warning()
  48.     */
  49.     var $warn = array();
  50.  
  51.     /**
  52.     * Print warnings?
  53.     * @var       array 
  54.     * @access    public
  55.     * @see      $haltOnWarning, $warn, warning()
  56.     */
  57.     var $printWarning = false;
  58.  
  59.     /**
  60.     * Call die() on warning?
  61.     * @var         boolean 
  62.     * @access    public
  63.     * @see       $warn, $printWarning, warning()
  64.     */
  65.     var $haltOnWarning = false;
  66.  
  67.     /**
  68.     * RegExp used to test for a valid blockname.
  69.     * @var    string 
  70.     */
  71.     var $checkblocknameRegExp = '';
  72.  
  73.     /**
  74.     * Functionnameprefix used when searching function calls in the template.
  75.     * @var    string 
  76.     */
  77.     var $functionPrefix = 'func_';
  78.  
  79.     /**
  80.     * Functionname RegExp.
  81.     * @var    string 
  82.     */
  83.     var $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*';
  84.  
  85.     /**
  86.     * RegExp used to grep function calls in the template.
  87.     *
  88.     * The variable gets set by the constructor.
  89.     *
  90.     * @var    string 
  91.     * @see    HTML_Template_IT()
  92.     */
  93.     var $functionRegExp = '';
  94.  
  95.     /**
  96.     * List of functions found in the template.
  97.     *
  98.     * @var    array 
  99.     */
  100.     var $functions         = array();
  101.  
  102.     /**
  103.     * List of callback functions specified by the user.
  104.     *
  105.     * @var    array 
  106.     */
  107.     var $callback         = array();
  108.  
  109.     /**
  110.     * Builds some complex regexps and calls the constructor
  111.     * of the parent class.
  112.     *
  113.     * Make sure that you call this constructor if you derive your own
  114.     * template class from this one.
  115.     *
  116.     * @see    HTML_Template_IT()
  117.     */
  118.     function HTML_Template_ITX($root '')
  119.     {
  120.  
  121.         $this->checkblocknameRegExp = '@' $this->blocknameRegExp . '@';
  122.         $this->functionRegExp = '@' $this->functionPrefix . '(' .
  123.                                 $this->functionnameRegExp . ')\s*\(@sm';
  124.  
  125.         $this->HTML_Template_IT($root);
  126.     // end func constructor
  127.  
  128.     function init()
  129.     {
  130.         $this->free();
  131.         $this->buildFunctionlist();
  132.         $this->findBlocks($this->template);
  133.         // we don't need it any more
  134.         $this->template = '';
  135.         $this->buildBlockvariablelist();
  136.  
  137.     // end func init
  138.  
  139.     /**
  140.     * Replaces an existing block with new content.
  141.     *
  142.     * This function will replace a block of the template and all blocks
  143.     * contained in the replaced block and add a new block insted, means
  144.     * you can dynamically change your template.
  145.     *
  146.     * Note that changing the template structure violates one of the IT[X]
  147.     * development goals. I've tried to write a simple to use template engine
  148.     * supporting blocks. In contrast to other systems IT[X] analyses the way
  149.     * you've nested blocks and knows which block belongs into another block.
  150.     * The nesting information helps to make the API short and simple. Replacing
  151.     * blocks does not only mean that IT[X] has to update the nesting
  152.     * information (relatively time consumpting task) but you have to make sure
  153.     * that you do not get confused due to the template change itself.
  154.     *
  155.     * @param    string      Blockname
  156.     * @param    string      Blockcontent
  157.     * @param    boolean     true if the new block inherits the content
  158.     *                        of the old block
  159.     * @return   boolean 
  160.     * @throws   IT_Error
  161.     * @see      replaceBlockfile(), addBlock(), addBlockfile()
  162.     * @access   public
  163.     */
  164.     function replaceBlock($block$template$keep_content = false)
  165.     {
  166.         if (!isset($this->blocklist[$block])) {
  167.             return new IT_Error(
  168.             "The block "."'$block'".
  169.             " does not exist in the template and thus it can't be replaced.",
  170.             __FILE____LINE__
  171.             );
  172.         }
  173.         if ('' == $template{
  174.             return new IT_Error('No block content given.'__FILE____LINE__);
  175.         }
  176.         if ($keep_content{
  177.             $blockdata $this->blockdata[$block];
  178.         }
  179.  
  180.         // remove all kinds of links to the block / data of the block
  181.         $this->removeBlockData($block);
  182.  
  183.         $template = "<!-- BEGIN $block -->" . $template . "<!-- END $block -->";
  184.         $parents $this->blockparents[$block];
  185.         $this->findBlocks($template);
  186.         $this->blockparents[$block$parents;
  187.  
  188.         // KLUDGE: rebuild the list for all block - could be done faster
  189.         $this->buildBlockvariablelist();
  190.  
  191.         if ($keep_content{
  192.             $this->blockdata[$block$blockdata;
  193.         }
  194.  
  195.         // old TODO - I'm not sure if we need this
  196.         // update caches
  197.  
  198.         return true;
  199.     // end func replaceBlock
  200.  
  201.     /**
  202.     * Replaces an existing block with new content from a file.
  203.     *
  204.     * @brother replaceBlock()
  205.     * @param    string    Blockname
  206.     * @param    string    Name of the file that contains the blockcontent
  207.     * @param    boolean   true if the new block inherits the content of the old block
  208.     */
  209.     function replaceBlockfile($block$filename$keep_content = false)
  210.     {
  211.         return $this->replaceBlock($block$this->getFile($filename)$keep_content);
  212.     // end func replaceBlockfile
  213.  
  214.     /**
  215.     * Adds a block to the template changing a variable placeholder
  216.     * to a block placeholder.
  217.     *
  218.     * Add means "replace a variable placeholder by a new block".
  219.     * This is different to PHPLibs templates. The function loads a
  220.     * block, creates a handle for it and assigns it to a certain
  221.     * variable placeholder. To to the same with PHPLibs templates you would
  222.     * call set_file() to create the handle and parse() to assign the
  223.     * parsed block to a variable. By this PHPLibs templates assume
  224.     * that you tend to assign a block to more than one one placeholder.
  225.     * To assign a parsed block to more than only the placeholder you specify
  226.     * in this function you have to use a combination of getBlock()
  227.     * and setVariable().
  228.     *
  229.     * As no updates to cached data is necessary addBlock() and addBlockfile()
  230.     * are rather "cheap" meaning quick operations.
  231.     *
  232.     * The block content must not start with <!-- BEGIN blockname -->
  233.     * and end with <!-- END blockname --> this would cause overhead and
  234.     * produce an error.
  235.     *
  236.     * @param    string    Name of the variable placeholder, the name must be unique
  237.     *                      within the template.
  238.     * @param    string    Name of the block to be added
  239.     * @param    string    Content of the block
  240.     * @return   boolean 
  241.     * @throws   IT_Error
  242.     * @see      addBlockfile()
  243.     * @access   public
  244.     */
  245.     function addBlock($placeholder$blockname$template)
  246.     {
  247.  
  248.         // Don't trust any user even if it's a programmer or yourself...
  249.         if ('' == $placeholder{
  250.  
  251.             return new IT_Error('No variable placeholder given.',
  252.                                 __FILE____LINE__
  253.                                 );
  254.  
  255.         else if '' == $blockname ||
  256.                     !preg_match($this->checkblocknameRegExp$blockname)
  257.         {
  258.  
  259.             return new IT_Error("No or invalid blockname '$blockname' given.",
  260.                     __FILE____LINE__
  261.                     );
  262.  
  263.         else if ('' == $template{
  264.  
  265.             return new IT_Error('No block content given.'__FILE____LINE__);
  266.  
  267.         else if (isset($this->blocklist[$blockname])) {
  268.  
  269.             return new IT_Error('The block already exists.',
  270.                                 __FILE____LINE__
  271.                             );
  272.  
  273.         }
  274.  
  275.         // find out where to insert the new block
  276.         $parents $this->findPlaceholderBlocks($placeholder);
  277.         if (0 == count($parents)) {
  278.  
  279.             return new IT_Error(
  280.                 "The variable placeholder".
  281.                 " '$placeholder' was not found in the template.",
  282.                 __FILE____LINE__
  283.             );
  284.  
  285.         else if count($parents> 1 {
  286.  
  287.             reset($parents);
  288.             while (list($k$parenteach($parents)) {
  289.                 $msg .= "$parent";
  290.             }
  291.             $msg substr($parent-2);
  292.  
  293.             return new IT_Error("The variable placeholder "."'$placeholder'".
  294.                                 " must be unique, found in multiple blocks '$msg'.",
  295.                                 __FILE____LINE__
  296.                                 );
  297.         }
  298.  
  299.         $template = "<!-- BEGIN $blockname -->" . $template . "<!-- END $blockname -->";
  300.         $this->findBlocks($template);
  301.         if ($this->flagBlocktrouble{
  302.             return false;    // findBlocks() already throws an exception
  303.         }
  304.         $this->blockinner[$parents[0]][$blockname;
  305.         $this->blocklist[$parents[0]] preg_replace(
  306.                     '@' $this->openingDelimiter . $placeholder .
  307.                     $this->closingDelimiter . '@',
  308.  
  309.                     $this->openingDelimiter . '__' $blockname '__' .
  310.                     $this->closingDelimiter,
  311.  
  312.                     $this->blocklist[$parents[0]]
  313.                 );
  314.  
  315.         $this->deleteFromBlockvariablelist($parents[0]$placeholder);
  316.         $this->updateBlockvariablelist($blockname);
  317.     /*
  318.     // check if any inner blocks were found
  319.     if(is_array($this->blockinner[$blockname]) and count($this->blockinner[$blockname]) > 0) {
  320.         // loop through inner blocks, registering the variable placeholders in each
  321.         foreach($this->blockinner[$blockname] as $childBlock) {
  322.             $this->updateBlockvariablelist($childBlock);
  323.         }
  324.     }
  325.     */
  326.         return true;
  327.     // end func addBlock
  328.  
  329.     /**
  330.     * Adds a block taken from a file to the template changing a variable
  331.     * placeholder to a block placeholder.
  332.     *
  333.     * @param      string    Name of the variable placeholder to be converted
  334.     * @param      string    Name of the block to be added
  335.     * @param      string    File that contains the block
  336.     * @brother    addBlock()
  337.     */
  338.     function addBlockfile($placeholder$blockname$filename)
  339.     {
  340.         return $this->addBlock($placeholder$blockname$this->getFile($filename));
  341.     // end func addBlockfile
  342.  
  343.     /**
  344.     * Returns the name of the (first) block that contains
  345.     * the specified placeholder.
  346.     *
  347.     * @param    string  Name of the placeholder you're searching
  348.     * @param    string  Name of the block to scan. If left out (default)
  349.     *                    all blocks are scanned.
  350.     * @return   string  Name of the (first) block that contains
  351.     *                    the specified placeholder.
  352.     *                    If the placeholder was not found or an error occured
  353.     *                    an empty string is returned.
  354.     * @throws   IT_Error
  355.     * @access   public
  356.     */
  357.     function placeholderExists($placeholder$block '')
  358.     {
  359.         if ('' == $placeholder{
  360.             new IT_Error('No placeholder name given.'__FILE____LINE__);
  361.             return '';
  362.         }
  363.  
  364.         if ('' != $block && !isset($this->blocklist[$block])) {
  365.             new IT_Error("Unknown block '$block'."__FILE____LINE__);
  366.             return '';
  367.         }
  368.  
  369.         // name of the block where the given placeholder was found
  370.         $found '';
  371.  
  372.         if ('' != $block{
  373.  
  374.             if (is_array($variables $this->blockvariables[$block])) {
  375.  
  376.                 // search the value in the list of blockvariables
  377.                 reset($variables);
  378.                 while (list($k$variableeach($variables)) {
  379.                     if ($k == $placeholder{
  380.                         $found $block;
  381.                         break;
  382.                     }
  383.                 }
  384.             }
  385.  
  386.         else {
  387.  
  388.             // search all blocks and return the name of the first block that
  389.             // contains the placeholder
  390.             reset($this->blockvariables);
  391.             while (list($blockname$variableseach($this->blockvariables)){
  392.  
  393.                 if (is_array($variables&& isset($variables[$placeholder])) {
  394.                     $found $blockname;
  395.                     break;
  396.                 }
  397.             }
  398.  
  399.         }
  400.  
  401.         return $found;
  402.     // end func placeholderExists
  403.  
  404.     /**
  405.     * Checks the list of function calls in the template and
  406.     * calls their callback function.
  407.     *
  408.     * @access    public
  409.     */
  410.     function performCallback()
  411.     {
  412.  
  413.         reset($this->functions);
  414.         while (list($func_id$functioneach($this->functions)) {
  415.  
  416.             if (isset($this->callback[$function['name']])) {
  417.  
  418.                 if ('' != $this->callback[$function['name']]['object']{
  419.                     $this->variableCache['__function' $func_id '__'=
  420.                         call_user_func(
  421.                         array(
  422.                         &$GLOBALS[$this->callback[$function['name']]['object']],
  423.                         $this->callback[$function['name']]['function']),
  424.                         $function['args']
  425.                        );
  426.                 else {
  427.                     $this->variableCache['__function' $func_id '__'=
  428.                             call_user_func(
  429.                             $this->callback[$function['name']]['function'],
  430.                             $function['args']
  431.                         );
  432.                 }
  433.  
  434.             }
  435.  
  436.         }
  437.  
  438.     // end func performCallback
  439.  
  440.     /**
  441.     * Returns a list of all function calls in the current template.
  442.     *
  443.     * @return   array 
  444.     * @access   public
  445.     */
  446.     function getFunctioncalls()
  447.     {
  448.         return $this->functions;
  449.     // end func getFunctioncalls
  450.  
  451.     /**
  452.     * Replaces a function call with the given replacement.
  453.     *
  454.     * @param    int       Function ID
  455.     * @param    string    Replacement
  456.     * @deprec
  457.     */
  458.     function setFunctioncontent($functionID$replacement)
  459.     {
  460.         $this->variableCache['__function' $functionID '__'$replacement;
  461.     // end func setFunctioncontent
  462.  
  463.     /**
  464.     * Sets a callback function.
  465.     *
  466.     * IT[X] templates (note the X) can contain simple function calls.
  467.     * "function call" means that the editor of the template can add
  468.     * special placeholder to the template like 'func_h1("embedded in h1")'.
  469.     * IT[X] will grab this function calls and allow you to define a callback
  470.     * function for them.
  471.     *
  472.     * This is an absolutely evil feature. If your application makes heavy
  473.     * use of such callbacks and you're even implementing if-then etc. on
  474.     * the level of a template engine you're reiventing the wheel... - that's
  475.     * actually how PHP came into life. Anyway, sometimes it's handy.
  476.     *
  477.     * Consider also using XML/XSLT or native PHP. And please do not push
  478.     * IT[X] any further into this direction of adding logics to the template
  479.     * engine.
  480.     *
  481.     * For those of you ready for the X in IT[X]:
  482.     *
  483.     * <?php
  484.     * ...
  485.     * function h_one($args) {
  486.     *    return sprintf('<h1>%s</h1>', $args[0]);
  487.     * }
  488.     *
  489.     * ...
  490.     * $itx = new HTML_Template_ITX( ... );
  491.     * ...
  492.     * $itx->setCallbackFunction('h1', 'h_one');
  493.     * $itx->performCallback();
  494.     * ?>
  495.     *
  496.     * template:
  497.     * func_h1('H1 Headline');
  498.     *
  499.     * @param    string    Function name in the template
  500.     * @param    string    Name of the callback function
  501.     * @param    string    Name of the callback object
  502.     * @return   boolean   False on failure.
  503.     * @throws   IT_Error
  504.     * @access   public
  505.     */
  506.     function
  507.     setCallbackFunction($tplfunction$callbackfunction$callbackobject '')
  508.     {
  509.  
  510.         if ('' == $tplfunction || '' == $callbackfunction{
  511.             return new IT_Error(
  512.                 "No template function "."('$tplfunction')".
  513.                 " and/or no callback function ('$callback') given.",
  514.                     __FILE____LINE__
  515.                 );
  516.         }
  517.         $this->callback[$tplfunction= array(
  518.                                           "function"    => $callbackfunction,
  519.                                           "object"        => $callbackobject
  520.                                         );
  521.  
  522.         return true;
  523.     // end func setCallbackFunction
  524.  
  525.     /**
  526.     * Sets the Callback function lookup table
  527.     *
  528.     * @param    array    function table
  529.     *                     array[templatefunction] =
  530.     *                        array(
  531.     *                                "function" => userfunction,
  532.     *                                "object" => userobject
  533.     *                        )
  534.     * @access    public
  535.     */
  536.     function setCallbackFuntiontable($functions)
  537.     {
  538.         $this->callback = $functions;
  539.     // end func setCallbackFunctiontable
  540.  
  541.     /**
  542.     * Recursively removes all data assiciated with a block, including all inner blocks
  543.     *
  544.     * @param    string  block to be removed
  545.     */
  546.     function removeBlockData($block)
  547.     {
  548.         if (isset($this->blockinner[$block])) {
  549.             foreach ($this->blockinner[$blockas $k => $inner{
  550.                 $this->removeBlockData($inner);
  551.             }
  552.  
  553.             unset($this->blockinner[$block]);
  554.         }
  555.  
  556.         unset($this->blocklist[$block]);
  557.         unset($this->blockdata[$block]);
  558.         unset($this->blockvariables[$block]);
  559.         unset($this->touchedBlocks[$block]);
  560.  
  561.     // end func removeBlockinner
  562.  
  563.     /**
  564.     * Returns a list of blocknames in the template.
  565.     *
  566.     * @return    array    [blockname => blockname]
  567.     * @access    public
  568.     * @see        blockExists()
  569.     */
  570.     function getBlocklist()
  571.     {
  572.         $blocklist = array();
  573.         foreach ($this->blocklist as $block => $content{
  574.             $blocklist[$block$block;
  575.         }
  576.  
  577.         return $blocklist;
  578.     // end func getBlocklist
  579.  
  580.     /**
  581.     * Checks wheter a block exists.
  582.     *
  583.     * @param    string 
  584.     * @return    boolean 
  585.     * @access    public
  586.     * @see        getBlocklist()
  587.     */
  588.     function blockExists($blockname)
  589.     {
  590.         return isset($this->blocklist[$blockname]);
  591.     // end func blockExists
  592.  
  593.     /**
  594.     * Returns a list of variables of a block.
  595.     *
  596.     * @param    string    Blockname
  597.     * @return    array    [varname => varname]
  598.     * @access    public
  599.     * @see        BlockvariableExists()
  600.     */
  601.     function getBlockvariables($block)
  602.     {
  603.         if (!isset($this->blockvariables[$block])) {
  604.             return array();
  605.         }
  606.  
  607.         $variables = array();
  608.         foreach ($this->blockvariables[$blockas $variable => $v{
  609.             $variables[$variable$variable;
  610.         }
  611.  
  612.         return $variables;
  613.     // end func getBlockvariables
  614.  
  615.     /**
  616.     * Checks wheter a block variable exists.
  617.     *
  618.     * @param    string    Blockname
  619.     * @param    string    Variablename
  620.     * @return    boolean 
  621.     * @access    public
  622.     * @see    getBlockvariables()
  623.     */
  624.     function BlockvariableExists($block$variable)
  625.     {
  626.         return isset($this->blockvariables[$block][$variable]);
  627.     // end func BlockvariableExists
  628.  
  629.     /**
  630.     * Builds a functionlist from the template.
  631.     */
  632.     function buildFunctionlist()
  633.     {
  634.         $this->functions = array();
  635.  
  636.         $template $this->template;
  637.         $num = 0;
  638.  
  639.         while (preg_match($this->functionRegExp$template$regs)) {
  640.  
  641.             $pos strpos($template$regs[0]);
  642.             $template substr($template$pos strlen($regs[0]));
  643.  
  644.             $head $this->getValue($template')');
  645.             $args = array();
  646.  
  647.             $this->template = str_replace($regs[0$head ')',
  648.                                 '{__function' $num '__}'$this->template
  649.                             );
  650.             $template str_replace($regs[0$head ')',
  651.                         '{__function' $num '__}'$template
  652.                         );
  653.  
  654.             while ('' != $head && $args2 $this->getValue($head',')) {
  655.                 $arg2 trim($args2);
  656.                 $args[('"' == $arg2{0|| "'" == $arg2{0}?
  657.                                     substr($arg21-1$arg2;
  658.                 if ($arg2 == $head{
  659.                     break;
  660.                 }
  661.                 $head substr($headstrlen($arg2+ 1);
  662.             }
  663.  
  664.             $this->functions[$num++= array(
  665.                                                 'name'    => $regs[1],
  666.                                                 'args'    => $args
  667.                                             );
  668.         }
  669.  
  670.     // end func buildFunctionlist
  671.  
  672.  
  673.     function getValue($code$delimiter{
  674.         if ('' == $code{
  675.             return '';
  676.         }
  677.  
  678.         if (!is_array($delimiter)) {
  679.             $delimiter = array$delimiter => true );
  680.         }
  681.  
  682.         $len         strlen($code);
  683.         $enclosed    = false;
  684.         $enclosed_by '';
  685.  
  686.         if (isset($delimiter[$code[0]])) {
  687.  
  688.             $i = 1;
  689.  
  690.         else {
  691.  
  692.             for ($i = 0; $i $len; ++$i{
  693.  
  694.                 $char $code[$i];
  695.  
  696.                 if (
  697.                         ('"' == $char || "'" == $char&&
  698.                         ($char == $enclosed_by || '' == $enclosed_by&&
  699.                         (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
  700.                     ){
  701.  
  702.                     if (!$enclosed{
  703.                         $enclosed_by $char;
  704.                     else {
  705.                         $enclosed_by "";
  706.                     }
  707.                     $enclosed !$enclosed;
  708.  
  709.                 }
  710.                 if (!$enclosed && isset($delimiter[$char])) {
  711.                     break;
  712.                 }
  713.             }
  714.  
  715.         }
  716.  
  717.         return substr($code0$i);
  718.     // end func getValue
  719.  
  720.  
  721.     /**
  722.     * Deletes one or many variables from the block variable list.
  723.     *
  724.     * @param    string    Blockname
  725.     * @param    mixed     Name of one variable or array of variables
  726.     *                      ( array ( name => true ) ) to be stripped.
  727.     */
  728.     function deleteFromBlockvariablelist($block$variables)
  729.     {
  730.         if (!is_array($variables)) {
  731.             $variables = array($variables => true);
  732.         }
  733.  
  734.         reset($this->blockvariables[$block]);
  735.         while (list($varname$valeach($this->blockvariables[$block])) {
  736.             if (isset($variables[$varname])) {
  737.                 unset($this->blockvariables[$block][$varname]);
  738.             }
  739.         }
  740.     // end deleteFromBlockvariablelist
  741.  
  742.     /**
  743.     * Updates the variable list of a block.
  744.     *
  745.     * @param    string    Blockname
  746.     */
  747.     function updateBlockvariablelist($block)
  748.     {
  749.         preg_match_all$this->variablesRegExp,
  750.                         $this->blocklist[$block]$regs
  751.                     );
  752.  
  753.         if (0 != count($regs[1])) {
  754.             foreach ($regs[1as $k => $var{
  755.                 $this->blockvariables[$block][$var= true;
  756.             }
  757.         else {
  758.             $this->blockvariables[$block= array();
  759.         }
  760.  
  761.         // check if any inner blocks were found
  762.         if (isset($this->blockinner[$block]&&
  763.             is_array($this->blockinner[$block]&&
  764.             count($this->blockinner[$block]> 0
  765.         {
  766.             /*
  767.              * loop through inner blocks, registering the variable
  768.              * placeholders in each
  769.              */
  770.             foreach($this->blockinner[$blockas $childBlock{
  771.                 $this->updateBlockvariablelist($childBlock);
  772.             }
  773.         }
  774.  
  775.     // end func updateBlockvariablelist
  776.  
  777.     /**
  778.     * Returns an array of blocknames where the given variable
  779.     * placeholder is used.
  780.     *
  781.     * @param    string    Variable placeholder
  782.     * @return    array    $parents    parents[0..n] = blockname
  783.     */
  784.     function findPlaceholderBlocks($variable)
  785.     {
  786.         $parents = array();
  787.         reset($this->blocklist);
  788.         while (list($blockname$contenteach($this->blocklist)) {
  789.             reset($this->blockvariables[$blockname]);
  790.             while (
  791.                 list($varname$valeach($this->blockvariables[$blockname]))
  792.             {
  793.                 if ($variable == $varname{
  794.                     $parents[$blockname;
  795.                 }
  796.             }
  797.         }
  798.  
  799.         return $parents;
  800.     // end func findPlaceholderBlocks
  801.  
  802.     /**
  803.     * Handles warnings, saves them to $warn and prints them or
  804.     * calls die() depending on the flags
  805.     *
  806.     * @param    string    Warning
  807.     * @param    string    File where the warning occured
  808.     * @param    int       Linenumber where the warning occured
  809.     * @see      $warn, $printWarning, $haltOnWarning
  810.     */
  811.     function warning($message$file ''$line = 0)
  812.     {
  813.         $message sprintf(
  814.                     'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
  815.                     $message,
  816.                     $file,
  817.                     $line
  818.                 );
  819.  
  820.         $this->warn[$message;
  821.  
  822.         if ($this->printWarning{
  823.             print $message;
  824.         }
  825.  
  826.         if ($this->haltOnWarning{
  827.             die($message);
  828.         }
  829.     // end func warning
  830.  
  831. // end class HTML_Template_ITX
  832. ?>

Documentation generated on Mon, 11 Mar 2019 14:16:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.